import java.io.ByteArrayOutputStream;
import java.io.InputStream;

/**
 * @file ReadFile.java
 * @author xiao
 * @mail 158430154@qq.com
 * @data 2014年5月5日 下午10:52:46
 * @description: 读取文档
 */
public class ReadFile {
	public String read(String filename) {
		String strReturn = "";
		filename = "/"+filename+".txt";
		InputStream in = null;
		ByteArrayOutputStream baos = null;

		try {
			in = getClass().getResourceAsStream(filename);
			baos = new ByteArrayOutputStream();
			// 循环读取数据
			int ch;
			while ((ch = in.read()) != -1) {
				baos.write(ch);
			}
			in.close();
			strReturn = new String(baos.toByteArray(), "UTF-8");
			baos.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("filename: " + filename);
		} finally {
			in = null;
		}
		return strReturn;
	}
}
